package cn.com.dcsgo.ioc.lifecycle;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;


/**
 * DemoBean
 *
 * @author Dcsgo
 * @since 2025/2/5 9:57
 */
@Component
//作用域配置
@Scope(scopeName = ConfigurableBeanFactory.SCOPE_SINGLETON)
public class DemoBean {
    /**
     * 方法名无要求，但必须是public void无参方法
     * 再使用@PostConstruct 注解即可
     */
    @PostConstruct
    public void init(){
        System.out.println(getClass().getSimpleName()+" post construct");
    }

    /**
     * 同上
     */
    @PreDestroy
    public void destroy(){
        System.out.println(getClass().getSimpleName()+" destroy");
    }
}
